package org.pettyfox.pfpay.utils;

import org.codehaus.plexus.util.StringUtils;
import org.springframework.util.DigestUtils;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.Random;
import java.util.UUID;

public class MD5Utils {

    private static String slat = "aisfjoas";
    private static int count = 10;

    /**
     * md5 随机签名，不可逆，每次签名生成不同，多次迭代
     * @param s
     * @return
     */
    public static String md5Random(String s) {
        if(StringUtils.isEmpty(s)){
            s = "";
        }
        s += slat;
        for(int i = 0;i<count;i++){
            s += new Random().nextFloat();
            s = DigestUtils.md5DigestAsHex(s.getBytes());
        }
       return s;
    }
    public static String md5Random() {
        String s = "asf";
        s += slat;
        for(int i = 0;i<count;i++){
            s += new Random().nextFloat();
            s = DigestUtils.md5DigestAsHex(s.getBytes());
        }
       return s;
    }
    public static String getUUID(){
        String s = UUID.randomUUID().toString();
        //去掉“-”符号
        return s.substring(0,8)+s.substring(9,13)+s.substring(14,18)+s.substring(19,23)+s.substring(24);
    }
    public static void main (String[] args) throws UnsupportedEncodingException, NoSuchAlgorithmException {
        System.out.println(md5Random("a"));
        System.out.println(md5Random("a"));

    }
}